package manager;

import java.sql.ResultSet;
import java.sql.SQLException;

import entity.Round;

public class RoundMgr {
	DatabaseMgr dbMgr;

	public RoundMgr() {
		dbMgr = new DatabaseMgr();
	}

	public void updateCurrentRoundNo(int roundNo) {
		dbMgr.openAndUpdateAndClose("update round set roundNo=?", roundNo);
	}

	public Round retrieveCurrentRound() {
		Round round = null;

		String sql = "select roundNo, "
				+ " (case when (roundEndDate is not null) then 'false' else 'true' end) AS isRoundOpen "
				+ " from round ";
		try {
			ResultSet rs = dbMgr.openAndRead(sql);
			while (rs.next()) {
				round = new Round(rs.getInt("roundNo"),
						rs.getBoolean("isRoundOpen"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		return round;
	}

}
